package fan_video.controller;

import fan_video.Utils.JwtUtils;
import fan_video.service.Interfaces.VideoFavorite_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class VideoFavorite_Controller {
    @Autowired
    VideoFavorite_Service videoFavorite_service;
    @RequestMapping("videoFavorite/add")
    //传入视频id，收藏分区，用户token即可添加收藏
    public String add_videoFavorite(int fvid, String category, @RequestHeader("token") String token) throws Exception {
        int user_id = JwtUtils.parseJit(token);
        return videoFavorite_service.add_videoFavorite(fvid,user_id,category);
    }
    @RequestMapping("videoFavorite/delete")
    //取消收藏，同上
    public String deleteFavorite(int fvid, String category, @RequestHeader("token") String token) throws Exception {
        int user_id = JwtUtils.parseJit(token);
        return videoFavorite_service.deleteFavorite(fvid,user_id,category);
    }
    @RequestMapping("videoFavorite/check")
    //检查用户是已经收藏当前视频
    public String check_videoFavorite(int fvid, @RequestHeader("token") String token) throws Exception {
        int user_id = JwtUtils.parseJit(token);
        return videoFavorite_service.check_videoFavorite(fvid,user_id);
    }
    @RequestMapping("videoFavorite/num")
    //获取视频的收藏数量
    public int videoFavorite_Num(int fvid){
        return videoFavorite_service.videoFavorite_Num(fvid);
    }

    @RequestMapping("videoFavorite/category/{category}")
    //获取自己的当前收藏夹A内的视频，category为收藏夹A
    public String videoFavorite_category(@PathVariable String category,@RequestHeader("token") String token) throws Exception {
        int user_id = JwtUtils.parseJit(token);
        return videoFavorite_service.favorite_video(user_id,category);
    }

    @RequestMapping("videoFavorite/category_show_able")
    //获取他人收藏夹视频，后续可能添加是否允许他人访问权限
    public String video_Favorite_show_able(int user_id,String category){
        return videoFavorite_service.favorite_video(user_id,category);
    }

    @RequestMapping("videoFavorite/categoryList")
    //获取当前用户的收藏夹列表
    public String videoFavorite_categoryList(int user_id) throws Exception {
        return videoFavorite_service.videoFavorite_categoryList(user_id);
    }

    @RequestMapping("videoFavorite/add_category")
    //新建新收藏夹
    public String add_category(String category,@RequestHeader("token") String token) throws Exception {
        return videoFavorite_service.add_category(category,token);
    }

    @RequestMapping("videoFavorite/delete_category")
    //删除某个收藏夹
    public String delete_category(String category,@RequestHeader("token") String token) throws Exception {
        return videoFavorite_service.delete_category(category,token);
    }

}
